package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.dto.QueryLogInfo;
import cn.kgc.ssm.entity.LogInfo;
import cn.kgc.ssm.mapper.LoginfoMapper;
import cn.kgc.ssm.service.LogInfoService;
import cn.kgc.ssm.util.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2023/10/28
 * @description
 */
@Service
public class LogInfoServiceImpl implements LogInfoService {

    @Resource
    private LoginfoMapper loginfoMapper;

    @Override
    public void addInfo(LogInfo logInfo) {
        loginfoMapper.addLoginfo(logInfo);
    }

    @Override
    public ResponseResult getPage(QueryLogInfo queryLogInfo) {

        PageHelper.startPage(queryLogInfo.getPage(),queryLogInfo.getLimit());
        List<LogInfo>  logInfos =  loginfoMapper.getList(queryLogInfo.getUsername());

        PageInfo<LogInfo> logInfoPageInfo = new PageInfo<>(logInfos);
        long total = logInfoPageInfo.getTotal();


        return ResponseResult.success(logInfos,total);
    }
}
